﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using UBConDemo.Models;

namespace UBConDemo
{
    /// <summary>
    /// Provised a way to apply styles based on UbConItemModel.IsCategoryNameItem property.
    /// </summary>
    public class UbConItemStyleSelector:StyleSelector
    {
        /// <summary>
        /// Selects a style based on UbConItemModel.IsCategoryNameItem property.
        /// </summary>
        public override Style SelectStyle(object item, DependencyObject container)
        {
            Style _headerStyle = null, _contentStyle = null;

            UbConItemModel model = item as UbConItemModel;
            ComponentResourceKey key = null;
            ResourceDictionary dictionary = null;
            if (model.IsCategoryNameItem)
            {
                key = new ComponentResourceKey()
                {
                    ResourceId = "GroupHeaderStyle",
                    TypeInTargetAssembly = typeof(ResourceManager)
                };

                dictionary = new ResourceDictionary()
                {
                    Source = new Uri("/UbConDemo;component/Themes/Styles.xaml", UriKind.Relative)
                };
                _headerStyle = dictionary[key] as Style;
                return _headerStyle;
            }
            else 
            {
                key = new ComponentResourceKey()
                {
                    ResourceId = "ItemContentStyle",
                    TypeInTargetAssembly = typeof(ResourceManager)
                };

                dictionary = new ResourceDictionary()
                {
                    Source = new Uri("/UbConDemo;component/Themes/Styles.xaml", UriKind.Relative)
                };
                _contentStyle = dictionary[key] as Style;
                return _contentStyle;
            }
        }
    }
}
